home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / pcp.idb / usr / pcp / bin / cron.pmlogmerge.z / cron.pmlogmerge
Text File  |  1997-04-03  |  5KB  |  221 lines

  1. #!/bin/sh
  2. # Copyright 1995, Silicon Graphics, Inc.
  3. # ALL RIGHTS RESERVED
  4. # UNPUBLISHED -- Rights reserved under the copyright laws of the United
  5. # States.   Use of a copyright notice is precautionary only and does not
  6. # imply publication or disclosure.
  7. # U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  8. # Use, duplication or disclosure by the Government is subject to restrictions
  9. # as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  10. # in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  11. # in similar or successor clauses in the FAR, or the DOD or NASA FAR
  12. # Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  13. # 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  14. # THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  15. # INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  16. # DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  17. # PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  18. # GRAPHICS, INC.
  19. #
  20. # merge a group of logfiles, e.g. all those for today
  21. #
  22. # default case, w/out arguments uses the default pmlogger filename
  23. # conventions for today's logs, namely `date +%y%m%d` for both the
  24. # input-basename and the output-name
  25. #
  26.  
  27. prog=`basename $0`
  28. tmp=/tmp/$$
  29. status=0
  30. trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
  31. rm -f $tmp.*
  32.  
  33. force=false
  34.  
  35. _abandon()
  36. {
  37.     echo "$prog: These error(s) are fatal, no output archive has been created."
  38.     status=1
  39.     exit
  40. }
  41.  
  42. _warning()
  43. {
  44.     echo "$prog: Trying to continue, although output archive may be corrupted."
  45.     force=false
  46. }
  47.  
  48. usage="Usage: $prog [-f] [input-basename ... output-name]"
  49.  
  50. # option parsing
  51. #
  52. while getopts f c
  53. do
  54.     case $c
  55.     in
  56.  
  57.     f)
  58.         force=true
  59.         ;;
  60.     
  61.     \?)    echo "$usage"
  62.         _abandon
  63.         ;;
  64.     esac
  65. done
  66. shift `expr $OPTIND - 1`
  67.  
  68. if [ $# -eq 0 ]
  69. then
  70.     inputlist=`date +%y%m%d`
  71.     output=$input
  72. elif [ $# -ge 2 ]
  73. then
  74.     inputlist=""
  75.     while [ $# -ge 2 ]
  76.     do
  77.     inputlist="$inputlist $1"
  78.     shift
  79.     done
  80.     output="$1"
  81. else
  82.     echo "$usage"
  83.     status=1
  84.     exit
  85. fi
  86.  
  87. fail=false
  88. mergelist=""
  89.  
  90. for input in $inputlist
  91. do
  92.     for file in $input.index
  93.     do
  94.     file=`basename $file .index`
  95.     empty=0
  96.     if [ ! -f "$file.index" ]
  97.     then
  98.         echo "$prog: Error: \"index\" file missing for archive \"$file\""
  99.         fail=true
  100.     elif [ ! -s "$file.index" ]
  101.     then
  102.         empty=`expr $empty + 1`
  103.     fi
  104.     if [ ! -f "$file.meta" ]
  105.     then
  106.         echo "$prog: Error: \"meta\" file missing for archive \"$file\""
  107.         fail=true
  108.     elif [ ! -s "$file.meta" ]
  109.     then
  110.         empty=`expr $empty + 1`
  111.     fi
  112.     if [ ! -f "$file.0" ]
  113.     then
  114.         echo "$prog: Error: \"volume 0\" file missing for archive \"$file\""
  115.         fail=true
  116.     elif [ ! -s "$file.0" ]
  117.     then
  118.         empty=`expr $empty + 1`
  119.     fi
  120.     if [ $empty -eq 3 ]
  121.     then
  122.         echo "$prog: Warning: archive \"$file\" is empty and will be skipped"
  123.     else
  124.         mergelist="$mergelist $file"
  125.     fi
  126.     done
  127. done
  128.  
  129. if [ -f $output.index ]
  130. then
  131.     echo "$prog: Error: \"index\" file already exists for output archive \"$output\""
  132.     fail=true
  133. fi
  134. if [ -f $output.meta ]
  135. then
  136.     echo "$prog: Error: \"meta\" file already exists for output archive \"$output\""
  137.     fail=true
  138. fi
  139. if [ -f $output.0 ]
  140. then
  141.     echo "$prog: Error: \"volume 0\" file already exists for output archive \"$output\""
  142.     fail=true
  143. fi
  144.  
  145. $fail && _abandon
  146.  
  147. i=0
  148. list=""
  149. part=0
  150. echo "Input archives to be merged:"
  151. for input in $mergelist
  152. do
  153.     for file in $input.index
  154.     do
  155.     if [ $i -ge 60 ]
  156.     then
  157.         echo "        -> partial merge to $tmp.$part"
  158.         if /usr/pcp/bin/pmlogmerge $list $tmp.$part
  159.         then
  160.         :
  161.         else
  162.         echo "$prog: pmlogmerge failed"
  163.         _warning
  164.         fi
  165.         list=$tmp.$part
  166.         part=`expr $part + 1`
  167.         i=0
  168.     fi
  169.     file=`basename $file .index`
  170.     list="$list $file"
  171.     echo "    $file\c"
  172.     numvol=`echo $file.[0-9]* | wc -w | sed -e 's/  *//g'`
  173.     if [ $numvol -gt 1 ]
  174.     then
  175.         echo " ($numvol volumes)"
  176.     else
  177.         echo
  178.     fi
  179.     i=`expr $i + 1`
  180.     done
  181. done
  182.  
  183. if /usr/pcp/bin/pmlogmerge $list $output
  184. then
  185.     :
  186. else
  187.     echo "$prog: pmlogmerge failed"
  188.     _warning
  189. fi
  190. echo "Output archive files:"
  191. for file in $output.meta $output.index $output.0
  192. do
  193.     if [ -f $file ]
  194.     then
  195.     ls -l $file
  196.     else
  197.     echo "$prog: Error: file \"$file\" not created"
  198.     force=false
  199.     fi
  200. done
  201.  
  202. if $force
  203. then
  204.     echo "Removing input archive files ...\c"
  205.     for input in $inputlist
  206.     do
  207.     for file in $input.index
  208.     do
  209.         file=`basename $file .index`
  210.         [ "$file" = "$output" ] && continue
  211.         rm -f $file.index $file.meta $file.[0-9]*
  212.     done
  213.     done
  214.     echo " done"
  215. fi
  216.  
  217. exit
  218.